package com.hyh.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

/**
 * 编码过滤器
 */
@WebFilter("/*")
public class CharsetEncodingFileter implements Filter {

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// 过滤器业务逻辑处理
		// 设置request编码
				request.setCharacterEncoding("utf-8");
		// 设置response编码
				response.setCharacterEncoding("utf-8");
	   
		System.out.println("执行了设置编码过滤器");		
		//继续在过滤器链上向下传递
		chain.doFilter(request, response);
	}

	/**
	 *获取配置信息
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// 
	}

}
